<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Vigilante extends CI_Controller {
    
        public function __construct() {
        parent::__construct();
        $this->load->library('form_validation');
        }
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
            $data = array(
                "ci" => $this->input->post("CI"),
                "nombre" => $this->input->post("Nombre"),
                "dir_v" => $this->input->post("Dir_v"),
                "f_nac" => $this->input->post("F_Nac"),                
            );
            
            $vig_ctt = array(
                "ci_vig" => $this->input->post("CI"),
                "cod_b" => $this->input->post("Cod_B"),
                "cod_s" => $this->input->post("Cod_S"),
                "f_ini" => $this->input->post("F_Ini"),
                "f_fin" => $this->input->post("F_Fin"),
                "pos_arma" => $this->input->post("Pos_arma"),
            );
            
            $vig_tel = array(
                "ci" => $this->input->post("CI"),
                "num_telf" => $this->input->post("Num_telf"),
            );
            
            
                        
            $tipo_op = $this->input->post("Operacion");
         
                switch ($tipo_op) {
                    case "Insertar":
                    {
                        
                        $this->form_validation->set_error_delimiters('<span class="mensaje-error">', '</span>');
                            if ($this->form_validation->run('Vigilante') === FALSE) {
                                
                                $this->load->view('dbwindows/Vigilante');
                                
                                
                            } else {                                
                                $this->load->model('vigilanteDB');
                                $this->vigilanteDB->Insert_Tabl($data);
                                $this->vigilanteDB->Insert_Table_v_tel($vig_tel);
                                $this->vigilanteDB->Insert_Table_vig_ctt($vig_ctt);                                
                                $this->load->view('Clean/Vigilante', $data);                                
                            }
                    }
                        break;
                    case "Actualizar":
                    {
                        
                        
                        
                    $this->form_validation->set_error_delimiters('<span class="mensaje-error">', '</span>');
                            if ($this->form_validation->run('updVigilante') === FALSE) {
                                $this->load->view('dbwindows/Vigilante');
                            } else {                                   
                            $this->load->model('vigilanteDB');
                            if ($this->vigilanteDB->update_entryvig($data,$vig_ctt,$vig_tel))
                                $this->load->view('Clean/Vigilante');
                            else
                                echo "Codigo no coindice, vaya atras en su navegador";    
                            }
                                   
                        
                    }
                        break;
                    case "Eliminar":
                    {
                        
                      $borrar = array (
                    'eliminar' => $this->input->post("CI"),     
                      ); // NOMBRE DEL INPUT COD o Ficha
                  
                    $this->form_validation->set_error_delimiters('<span class="mensaje-error">', '</span>');
                            if ($this->form_validation->run('Eliminarvigilante') === FALSE) {
                                $this->load->view('dbwindows/Vigilante');
                            } else {
                                $this->load->model('vigilanteDB');     
                                    if ($this->vigilanteDB->borrar_tablavigilante($borrar))
                                        $this->load->view('Clean/Vigilante');
                                    else   {         
                                        echo "Ficha o Codigo inexistente en la relacion o tabla" ;
                                    ?>
                                    <br>
                                    <?php
                                        echo "Haga atras en su navegador para continuar"; 
                                    }
                            }    
                          
                        
                    }
                        break;
                    default:
                        echo "nothing happens";
                }
            
            
                 
	}
        

}